package com.woniuxy.controller;

import com.woniuxy.domain.*;
import com.woniuxy.dto.*;
import com.woniuxy.parameter.BugclassifyParam;
import com.woniuxy.parameter.BuglevelParam;
import com.woniuxy.parameter.BugpriorityParam;
import com.woniuxy.parameter.BugstateParam;
import com.woniuxy.service.*;
import com.woniuxy.util.BeanCopyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName StateController
 * @Description 缺陷列表界面在分配任务时需要添加的如优先级,缺陷分类,严重程度增删改查
 * @Author Joker
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/buttonStatement")
@Api(tags = "状态显示控制器")
public class ButtonStatementController {
    @Resource
    private BuglevelService buglevelService;
    @Resource
    private BugpriorityService bugpriorityService;
    @Resource
    private BugstateService bugstateService;
    @Resource
    private BugclassifyService bugclassifyService;
    @Resource
    private ProjectService projectService;
    @Resource
    private UserService userService;
    /**
     * @Author Joker
     * @Description 查询t_buglevel表查询出优先级返回前端
     * @Date  
     * @Param []
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("搜索buglevel等级下拉框")
    @GetMapping("/buglevel")
    public DtoJSONResult showBuglevel(){
        List<Buglevel> list = buglevelService.list();
        List<DtoBuglevel> dtoBuglevels = BeanCopyUtil.copyListProperties(list, DtoBuglevel::new);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,dtoBuglevels);
    }
    /**
     * @Author Joker
     * @Description 根据前端传过来的值来进行表格新增
     * @Date  
     * @Param [buglevelParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("新增buglevel等级")
    @PostMapping("/buglevel")
    public DtoJSONResult addBuglevel(BuglevelParam buglevelParam){
        Buglevel buglevel = new Buglevel();
        BeanUtils.copyProperties(buglevelParam,buglevel);
        buglevelService.save(buglevel);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传过来的id值,来进行全部更新
     * @Date  
     * @Param [buglevelParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("更新buglevel等级")
    @PutMapping("/buglevel")
    public DtoJSONResult updateBuglevel(BuglevelParam buglevelParam){
        Buglevel buglevel = new Buglevel();
        BeanUtils.copyProperties(buglevelParam,buglevel);
        //给domain类复制,根据domain的主键id进行更新
        buglevelService.saveOrUpdate(buglevel);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传的id删除t_buglevel表单字段
     * @Date  
     * @Param [id]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("删除buglevel等级")
    @DeleteMapping("/buglevel")
    public DtoJSONResult deleteBuglevel(int id){
        buglevelService.removeById(id);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 查询t_bugpriority表查询出优先级返回前端
     * @Date
     * @Param []
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("搜索bugpriority等级下拉框")
    @GetMapping("/bugpriority")
    public DtoJSONResult showBugpriority(){
        List<Bugpriority> list = bugpriorityService.list();
        List<DtoBugpriority> dtoBugpriorities = BeanCopyUtil.copyListProperties(list, DtoBugpriority::new);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,dtoBugpriorities);
    }
    /**
     * @Author Joker
     * @Description 根据前端传过来的值来进行表格新增
     * @Date  
     * @Param [bugpriorityParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("新增bugpriority等级")
    @PostMapping("/bugpriority")
    public DtoJSONResult addBugpriority(BugpriorityParam bugpriorityParam){
        Bugpriority bugpriority = new Bugpriority();
        BeanUtils.copyProperties(bugpriorityParam,bugpriority);
        bugpriorityService.save(bugpriority);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传过来的id值,来进行全部更新
     * @Date
     * @Param [bugpriorityParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("更新bugpriority等级")
    @PutMapping("/bugpriority")
    public DtoJSONResult updateBugpriority(BugpriorityParam bugpriorityParam){
        Bugpriority bugpriority = new Bugpriority();
        BeanUtils.copyProperties(bugpriorityParam,bugpriority);
        //给domain类复制,根据domain的主键id进行更新
        bugpriorityService.saveOrUpdate(bugpriority);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传的id删除t_bugpriority表单字段
     * @Date  
     * @Param [id]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("删除bugpriority等级")
    @DeleteMapping("/bugpriority")
    public DtoJSONResult deleteBugpriority(int id){
        bugpriorityService.removeById(id);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 查询t_bugstate表查询出优先级返回前端
     * @Date
     * @Param []
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("搜索Bugstate等级下拉框")
    @GetMapping("/bugstate")
    public DtoJSONResult showBugstate(){
        List<Bugstate> list = bugstateService.list();
        List<DtoBugstate> dtoBugstates = BeanCopyUtil.copyListProperties(list, DtoBugstate::new);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,dtoBugstates);
    }
    /**
     * @Author Joker
     * @Description 根据前端传过来的值来进行表格新增
     * @Date  
     * @Param [bugstateParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("新增Bugstate等级")
    @PostMapping("/bugstate")
    public DtoJSONResult addBugstate(BugstateParam bugstateParam){
        Bugstate bugstate = new Bugstate();
        BeanUtils.copyProperties(bugstateParam,bugstate);
        bugstateService.save(bugstate);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传过来的id值,来进行全部更新
     * @Date
     * @Param [bugstateParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("更新Bugstate等级")
    @PutMapping("/bugstate")
    public DtoJSONResult updateBugstate(BugstateParam bugstateParam){
        Bugstate bugstate = new Bugstate();
        BeanUtils.copyProperties(bugstateParam,bugstate);
        //给domain类复制,根据domain的主键id进行更新
        bugstateService.saveOrUpdate(bugstate);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传的id删除t_bugstate表单字段
     * @Date  
     * @Param [id]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("删除Bugstate等级")
    @DeleteMapping("/bugstate")
    public DtoJSONResult deleteBugstate(int id){
        bugstateService.removeById(id);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 查询t_bugclassify表查询出优先级返回前端
     * @Date
     * @Param []
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("搜索bugclassify等级下拉框")
    @GetMapping("/bugclassify")
    public DtoJSONResult showBugclassify(){
        System.out.println("-------------------------------");
        List<Bugclassify> list = bugclassifyService.list();
        List<DtoBugclassify> dtoBugclassifies = BeanCopyUtil.copyListProperties(list, DtoBugclassify::new);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,dtoBugclassifies);
    }
    /**
     * @Author Joker
     * @Description 根据前端传过来的值来进行表格新增
     * @Date  
     * @Param [bugclassifyParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("新增bugclassify等级")
    @PostMapping("/bugclassify")
    public DtoJSONResult addBugclassify(BugclassifyParam bugclassifyParam){
        Bugclassify bugclassify = new Bugclassify();
        BeanUtils.copyProperties(bugclassifyParam,bugclassify);
        bugclassifyService.save(bugclassify);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传过来的id值,来进行全部更新
     * @Date
     * @Param [bugclassifyParam]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("更新bugclassify等级")
    @PutMapping("/bugclassify")
    public DtoJSONResult updateBugclassify(BugclassifyParam bugclassifyParam){
        Bugclassify bugclassify = new Bugclassify();
        BeanUtils.copyProperties(bugclassifyParam,bugclassify);
        //给domain类复制,根据domain的主键id进行更新
        bugclassifyService.saveOrUpdate(bugclassify);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 通过前端传的id删除t_bugclassify表单字段
     * @Date  
     * @Param [id]
     * @Return com.woniuxy.dto.JSONResult
     **/
    @ApiOperation("删除bugclassify等级")
    @DeleteMapping("/bugclassify")
    public DtoJSONResult deleteBugclassify(int id){
        bugclassifyService.removeById(id);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,null);
    }
    /**
     * @Author Joker
     * @Description 下拉框的搜索查询
     * @Date  
     * @Param []
     * @Return com.woniuxy.dto.DtoJSONResult
     **/
    @ApiOperation("搜索查询项目下拉框")
    @GetMapping("/showProject")
    public DtoJSONResult showProject(){
        List<Project> list = projectService.list();
        List<DtoProject> dtoProjects = BeanCopyUtil.copyListProperties(list, DtoProject::new);
        return new DtoJSONResult(DtoJSONResultCode.SUCCESS.getCode(), DtoJSONResultCode.SUCCESS.getMessage(),null,dtoProjects);
    }



}
